<template>
	<view>
		<image class="logoImg" src="https://obs-4a40.obs.cn-southwest-2.myhuaweicloud.com/shop/logo.jpg" mode=""></image>
		<button class="authBtn" open-type="getUserInfo" @getuserinfo="getInfo">
			确认授权
		</button>
	</view>
</template>

<script>
	const qs = require('qs');
	export default {
		data() {
			return {
					form:0
			}
		},
		onLoad(res) {
			this.from=res.from;
		},
		methods: {
			getInfo(e) {
				console.log(e.detail)
				let res = e.detail;
				const datas = qs.stringify({
					code: wx.getStorageSync('code'),
					rawData: res.rawData,
					signature: res.signature,
					encrypteData: res.encryptedData,
					iv: res.iv,
					wx:2
				});
				uni.setStorageSync('avatarUrl',res.userInfo.avatarUrl);
				uni.setStorageSync('nickName',res.userInfo.nickName);
				const requestParam = {
					url: '/weixin/ma/login',
					method: "POST",
					data: datas,
					callBack: (req) => {
						console.log(req)
						uni.setStorageSync('Token', req.data);
						setTimeout(()=>{
							uni.navigateBack({});
						},500)
					}
				}
				this.$http.login(requestParam);
				// wx.request({
				// 	url: 'http://192.168.0.140:8080/weixin/ma/login', //仅为示例，
				// 	data: datas,
				// 	method: 'POST',
				// 	header: {
				// 		"content-type": "application/x-www-form-urlencoded",
				// 	},
				// 	success: function(data) {
				// 		uni.setStorageSync('Token',data.data.data);
				// 		uni.navigateBack({})
				// 	}
				// })
				
			}

		}
	}
</script>

<style>
	.logoImg {
		width: 200rpx;
		height: 200rpx;
		display: block;
		margin: 220rpx auto;
	}

	.authBtn {
		width: 300rpx;
		height: 46px;
		color: #fff;
		font-size: 32rpx;
		background: rgb(27, 91, 67);
	}
</style>
